//
//  NewsDetailModel.m
//  MyAppDemo
//
//  Created by 千锋 on 15/12/5.
//  Copyright (c) 2015年 Aike. All rights reserved.
//

#import "NewsDetailModel.h"
#import "GDataXMLNode.h"

@implementation NewsDetailModel

+(NewsDetailModel *)parseXMLWithData:(NSData *)data{
    //将二进制数据转换为DOM文档
    GDataXMLDocument * document = [[GDataXMLDocument alloc]initWithData:data options:0 error:nil];
    //定义路径  查找节点
    NSString * newsPath = @"/oschina/news";
    //返回所有节点
    NSArray * newsElementArray = [document nodesForXPath:newsPath error:nil];
    //定义数据 存储所有将节点转换为模型对象
    // NSMutableArray * newsDetailArray = [[NSMutableArray alloc]init];
    NewsDetailModel * model = [[NewsDetailModel alloc]init];
    for (GDataXMLElement * element in newsElementArray) {
        //创建模型对象
        
        //读取ID
        GDataXMLNode * idNode = [element childAtIndex:0];
        model.ID = idNode.stringValue;
        GDataXMLNode * titleNode = [element childAtIndex:1];
        model.title = titleNode.stringValue;
        GDataXMLNode * urlNode = [element childAtIndex:2];
        model.url = urlNode.stringValue;
        GDataXMLNode * bodyNode = [element childAtIndex:3];
        model.body = bodyNode.stringValue;
        //        GDataXMLNode * commentCountNode = [element childAtIndex:3];
        //        model.commentCount = commentCountNode.stringValue;
        //        GDataXMLNode * authorNode = [element childAtIndex:4];
        //        model.author = authorNode.stringValue;
        //        GDataXMLNode * authoridNode = [element childAtIndex:5];
        //        model.authorid = authoridNode.stringValue;
        //        GDataXMLNode * pubDateNode = [element childAtIndex:6];
        //        model.pubDate = pubDateNode.stringValue;
        //        GDataXMLNode * newstypeNode = [element childAtIndex:7];
        //        model.newstype = newstypeNode.stringValue;
        
        
    }
    return model;
    
    
}



@end
